<template>
  <div><div :class="ischeck=='classification'||ischeck=='inventory'||ischeck=='soleing'?'black':'header'">
    <div class="nav">
      <a href="javascript:;" class="logo">LOGO</a>
      <a href="javascript:;" v-for='(item,index) of nav' :key=index @click='jumpTo(item.target)'
        :class="item.target==ischeck?'checked':''">{{item.name}}</a>
    </div>
    <div class="login-entrance" v-if="this.$store.state.uid==''">
      <a href="javascript:;">注销</a>
      <a href="javascript:;" @click="login">登录</a>
    </div>
    <div class="login-entrance" v-else>
      <div class="center"><span style="padding:0 0.625rem;border-left: white 0.1rem solid;">{{name}}</span></div>
      <a href="javascript:;" style="border: none;">
        <el-dropdown>
          <span class="el-dropdown-link">
            <img :src="'http://127.0.0.1:3000/'+this.$store.state.userImg" alt="头像">
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item>设置</el-dropdown-item>
            <el-dropdown-item @click.native='logout'>退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>

      </a>
        <div class="user-ball center" @click="jumpTo('inventory')"><a href="javascript:;" >个人仓库</a></div>
        <div class="soleing center" @click="jumpTo('soleing')"><a href="javascript:;">在售</a></div>
    </div>
  </div>
  <div class="header-after"></div>
  </div>

</template>

<script>
  export default {
    components: {},
    props: {
      //接收父组件数据的类型
      ischeck: {
        default: ''
      }
    },
    name: 'my-header',
    data() {
      return {
        nav: [{
          name: "首页",
          target: 'index',
        }, {
          name: "订单",
          target: 'indent',
        }, {
          name: "购物车",
          target: 'showcar',
        }, {
          name: "分类",
          target: 'classification',
        }],
        name:this.$store.state.uname
      }
    },
    methods: {
      jumpTo(target) {
        if (this.ischeck !== target) {
          console.log(this.ischeck)
          this.$router.replace({
            path: `/${target}`
          })
        }

      },
      parenteven(data) {
        this.isLogin = data
      },
      login() {
        this.$router.replace({
          path: '/login'
        })
      },
      logout() {
        // 先退出到一个空白页面再有空白页面跳转至index 有效避免闪屏  方法1
        // 方法2直接使用this.$router.go(0)
        this.$store.commit('login', 0)
        this.$router.push('/index');
        this.$router.go(0)
      },
    },
    created() {
      console.log(this.uid)
    }
  }
</script>
<style scoped>
  .black{
    background-color: rgb(16, 20, 26);
  }
  .header{
      background-image: linear-gradient(to right, #392541, #79484b, #4e2140);
  }
  .header,.black {
    /* background-color: rgb(16, 20, 26); */
    width: 100%;
/*    position: fixed;
    z-index: 99; */
    display: flex;
    justify-content: center;
    align-items: center;
  }

/*  .header-after {
    width: 100%;
    display: block;
    height: 4.375rem;
  } */

  .nav {
    display: inline-block;
    width: 70%;
    display: flex;
    justify-content: left;
    padding-left: 1rem;
  }

  .nav a {
    padding: 1rem;
    text-align: center;
    display: flex;
    align-items: center;
  }

  .nav a+a:hover {
    border-bottom: white 0.2rem solid;
  }

  .checked {
    border-bottom: white 0.2rem solid;

  }

  .nav a:@click {
    border-bottom: white 0.2rem solid;
  }

  .el-dropdown-link {
    color: white;
  }

  .nav a,
  .login-entrance a {
    text-decoration: none;
    color: whitesmoke;
  }

  .nav a:first-child {
    padding: 0.5rem 1rem;
    font-size: 2.5rem;
  }

  .login-entrance {
    width: 30%;
    display: flex;
    flex-direction: row-reverse;
  }

  .login-entrance a {
    padding: 0 0.5rem;
  }

  .login-entrance a:last-child {
    border-right: white 0.1rem solid;
  }

  .login-entrance a  img {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    margin: 0.5rem;
  }
   .login-entrance .center{
     display: flex;
     align-items: center;
   }
  .login-entrance span:first-child{
    color: white;
  }

</style>
